﻿using System;
using System.Linq;

namespace TicTacToe.Core.Statistics
{
    public sealed class TurnID
    {
        readonly Guid mId;
        readonly GameID mGame;
        readonly PlayerID mPlayer;
        readonly DateTime mTime;
        readonly int mIndex;
        readonly int mX1;
        readonly int mX2;
        readonly int mX3;

        public Guid Id { get { return mId; } }
        public GameID Game { get { return mGame; } }
        public PlayerID Player { get { return mPlayer; } }
        public DateTime Time { get { return mTime; } }
        public int Index { get { return mIndex; } }
        public int X1 { get { return mX1; } }
        public int X2 { get { return mX2; } }
        public int X3 { get { return mX3; } }

        public static implicit operator Guid(TurnID gid)
        {
            return gid.Id;
        }

        internal TurnID(GameID game, PlayerID player, DateTime time, int index, params int[] coordinates)
        {
            mId = Guid.NewGuid();
            mGame = game;
            mPlayer = player;
            mTime = time;
            mIndex = index;

            if (coordinates.Length != 3 || coordinates.Any(n => 0 > n || n > 3))
                throw new ArgumentException();

            mX1 = coordinates[0];
            mX2 = coordinates[1];
            mX3 = coordinates[2];
        }

        internal TurnID(Guid id, GameID game, PlayerID player, DateTime time, int index, params int[] coordinates)
        {
            mId = id;
            mGame = game;
            mPlayer = player;
            mTime = time;
            mIndex = index;

            if (coordinates.Length != 3 || coordinates.Any(n => 0 > n || n > 3))
                throw new ArgumentException();

            mX1 = coordinates[0];
            mX2 = coordinates[1];
            mX3 = coordinates[2];
        }
    }
}
